<!--
 * @Description: 新增维修项目
 * @Autor: 何兴家
 * @Date: 2020-12-08 13:22:24
 * @LastEditors: 何兴家
 * @LastEditTime: 2021-01-26 20:58:17
-->
<template>
  <div>
    <TopFilter ref="topFilter" :list="topFilterList" :labelWidth="100" :cols="4" @filterChange="handleSearch" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="repair_repairReception_customer_addRepairPart"
      :columns="columns"
      :fetchapi="fetchapi"
      height="auto"
      :params="fetchParams"
      :datakey="'rows'"
      selectionType="single"
      :onRowSelectChange="handleTableRowSelect"
      :onSyncTableData="handleSyncTableData"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>

    <div class="dialogBottmView">
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleConfirm">确定</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { confirmAction, notifyAction, findFormItem, findTableItem } from '@/utils';

import { getWxproductList } from '@/api/repair/common';

export default {
  props: ['modelId'],
  mixins: [dictionary],
  data() {
    this.selectedRows = [];
    return {
      topFilterList: this.createTopFIlterList(),
      columns: this.createTableColumns(),
      fetchapi: getWxproductList,
      fetchParams: { xhrAbort: true, modelId: '' },
      syncTableData: [] // 同步的table数据
    };
  },
  mounted() {
    this.fetchParams.modelId = this.modelId;
  },
  methods: {
    createTopFIlterList() {
      return [
        {
          type: 'INPUT',
          label: '维修项目代码',
          fieldName: 'labourCode',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '维修项目名称',
          fieldName: 'labourName',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '项目来源',
          fieldName: 'oemTag',
          itemList: this.createDictList('1045', [10451003])
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          }
        },
        {
          title: '维修项目代码',
          dataIndex: 'LABOUR_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '维修项目名称',
          dataIndex: 'LABOUR_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '标准工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '索赔工时',
          dataIndex: 'CLAIM_LABOUR',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '项目来源',
          dataIndex: 'DATA_SOURCES',
          sorter: true,
          filter: true,
          filterType: 'input',
          dictItems: this.createDictList('1045')
        },
        {
          title: '创建日期',
          dataIndex: 'CREATED_AT',
          sorter: true,
          filter: true,
          filterType: 'date'
        },
        {
          title: '更新日期',
          dataIndex: 'UPDATED_AT',
          sorter: true,
          filter: true,
          filterType: 'date'
        }
      ];
    },
    collapseHandle() {
      this.nextTick(() => {
        this.refs.table.EXECUTE_RESET_HEIGHT();
      });
    },
    // 点击搜索
    handleSearch(e) {
      this.fetchParams = Object.assign({}, this.fetchParams, e, { xhrAbort: false });
    },
    // 同步table数据
    handleSyncTableData(list) {
      this.syncTableData = list;
    },
    // table行项选择变化
    handleTableRowSelect(list) {
      this.selectedRows = list;
    },
    // 点击取消
    handleCancel() {
      this.$emit('close');
    },
    // 点击确定
    handleConfirm() {
      if (!this.selectedRows.length) notifyAction('请选择维修项目', 'warning');
      delete this.selectedRows[0].ITEM_ID;

      this.$emit('onConfirm', this.selectedRows);
    }
  }
};
</script>

<style scoped></style>
